/**
 * Created by MyPC on 2017/6/18.
 */
let mysql = require('../../common/connection');
let dao = {};
// 获取全部标签
dao.listByAll = function () {
  let sql = 'SELECT `id`,`names`,`counts` FROM `t_b_tags` WHERE `delete_time` IS NULL';
  let arr = [];
  return mysql.query(sql, arr);
}
// 查询(带分页)
dao.listByPage = function () {

}
// 新增
dao.save = function (params) {
  let sql = 'INSERT INTO `t_b_tags`(NAMES) VALUE(?)';
  let arr = [];
  if (params.names !== undefined) {
    arr.push(params.names);
  }
  return mysql.query(sql, arr);
}
// 根据id修改
dao.updateById = function (params) {
  let sql = 'UPDATE `t_b_tags` SET NAMES=? ';
  let arr = [];
  if (params.names !== undefined) {
    arr.push(params.names);
  }
  if (params.id !== undefined) {
    sql += 'where id=?';
    arr.push(params.id);
  }
  return mysql.query(sql, arr);
}
// 根据id删除
dao.removeById = function (id) {
  let sql = 'update `t_b_tags` set delete_time=now() WHERE  id=?';
  let arr = [];
  if (id !== undefined) {
    arr.push(id);
  }
  return mysql.query(sql, arr);
}

module.exports = dao;